package com.netdisk.controller;

import com.netdisk.dto.request.file.AddFavoriteDTO;
import com.netdisk.dto.response.file.FavoriteDTO;
import com.netdisk.dto.response.file.FavoriteListDTO;
import com.netdisk.service.FavoriteService;
import com.netdisk.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "收藏管理")
@RequestMapping("/favorite")
@RestController
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;
    @ApiOperation(value = "添加收藏")
    @PostMapping("/add")
    public Result<Object> addFavorite(AddFavoriteDTO addFavoriteDTO){
        favoriteService.addFavorite(addFavoriteDTO);
        return Result.success();
    }

    @ApiOperation(value = "取消收藏")
    @DeleteMapping("/remove")
    public Result<Object> cancelFavorite(Integer userId,Integer fileId){
        favoriteService.cancelFavorite(userId,fileId);
        return Result.success();
    }

    @ApiOperation(value = "获取收藏文件列表")
    @GetMapping("/list")
    public Result<FavoriteListDTO> getFavoriteList(Integer userId){
        List<FavoriteDTO> list = favoriteService.getFavoriteListById(userId);
        Integer total = favoriteService.getFavoriteCountById(userId);
        FavoriteListDTO favoriteListDTO = new FavoriteListDTO();
        favoriteListDTO.setList(list);
        favoriteListDTO.setTotal(total);
        return Result.success(favoriteListDTO);
    }

    @ApiOperation(value = "检查文件是否已收藏")
    @GetMapping("/check")
    public Result<Boolean> isFavorite(Integer userId, Integer fileId){
        boolean isFavorite = favoriteService.isFavorite(userId,fileId);
        return Result.success(isFavorite);
    }


}
